home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / CUGUK / PROG_TOO / C013.ZIP / CAT.C < prev    next >
Text File  |  1990-01-19  |  2KB  |  61 lines

  1. /********************************************************************
  2.  * C Users Group (U.K) C Source Code Library File CUGLIB.013        *
  3.  * Inquiries to: M. Houston, 36 Whetstone Clo. Farquhar Rd.         *
  4.  * Edgbaston, Birmingham B15 2QN ENGLAND                *
  5.  ********************************************************************
  6.  * File name: cat.c
  7.  * Program name:cat 
  8.  * Source of file: Ron Wellstead
  9.  * Purpose: An MS-DOS copy of the UNIX utility of the same name.
  10.  * Changes: <who what when & why major changes have been made>      
  11.  ********************************************************************/
  12.  
  13. /*
  14.  *
  15.  *    @(#) cat.c 1.2 87/07/27 
  16.  *
  17.  *    UNIX style cat utility for dos
  18.  *
  19.  *    copyright (c) 1987 Ron Wellsted.
  20.  *    This software is provided on the understanding that it is
  21.  *    NOT to be used for commercial gain. It may be freely distributed
  22.  *    in source or object form among amateur and hobby computer users ONLY!
  23.  *
  24.  *    copies a file (or stdin) to stdout.
  25.  *    usage: cat [files..]
  26.  *    written for Microsoft C, link with setargv.obj to expand wildcards
  27.  *
  28.  */
  29. #include    <stdio.h>
  30.  
  31. char what[]="@(#) cat VR 1.0.0 15 Jul 1987";
  32.  
  33. main(argc,argv)
  34. int argc;
  35. char *argv[];
  36. {
  37.     FILE *fp;
  38.  
  39.     if (argc==1)    /* no args; copy standard input */
  40.         filecopy(stdin);
  41.     else
  42.         while (--argc>0)
  43.             if ((fp=fopen(*++argv,"r"))==NULL) {
  44.                 fprintf(stderr,"cat: can't open %s\n",*argv);
  45.                 exit(1);
  46.             } else {
  47.                 filecopy(fp);
  48.                 fclose(fp);
  49.             }
  50.     exit(0);
  51. }
  52.  
  53. filecopy(fp)
  54. FILE *fp;
  55. {
  56.     int c;
  57.  
  58.     while ((c=getc(fp))!=EOF)
  59.         putchar(c);
  60. }
  61.